<template>
	<view>
		<!-- 地址 -->
		<my-address></my-address>
		<!-- 购物车列表 -->
		<view class="cart">
			<!-- 标题 -->
			<view class="cart-title">
				<uni-icons type="shop" size="20"></uni-icons>
				<text>购物车</text>
			</view>
			<!-- 商品列表 -->
			<view class="cart-list">
				<uni-swipe-action>
					<block v-for="(item,index) in cart" :key="index">
						<!-- right-options 右侧选项内容及样式 -->
						<uni-swipe-action-item :right-options="options" @click="removeGoods(item)">
							<my-goods @num-change="numChange" @radio-click="goodsStateChange" :showNum="true" :showRadio="true" :goods="item"></my-goods>
						</uni-swipe-action-item>
					</block>
				</uni-swipe-action>
				
			</view>
			
		</view>
	</view>
</template>

<script>
	import {mapState, mapMutations} from 'vuex'
	import tabBarMixins from '../../mixins/tabBarMixins.js'
	export default {
		mixins: [tabBarMixins],
		computed: {
			...mapState('m_cart', ['cart'])
		},
		data() {
			return {
				options: [
					{
						text: '删除',
						style: {
							backgroundColor: '#ea4350',
							color: '#fff'
						}
					}
				]
			}
		},
		methods: {
			...mapMutations('m_cart', ['updateGoodsState', 'updateGoodsCount', 'updateDelGoods']),
			// 删除商品
			removeGoods(goods) {
				this.updateDelGoods(goods)
			},
			// 商品数量改变时
			numChange(goods) {
				// 修改商品数量
				this.updateGoodsCount(goods)
			},
			// 切换goods-state状态
			goodsStateChange(goods) {
				// console.log(goods)
				// 更改选中状态
				this.updateGoodsState(goods)
			}
		}
	}
</script>

<style lang="scss">
.cart {
	.cart-title {
		display: flex;
		align-items: center;
		height: 40px;
		border-bottom: 1px solid #eee;
		padding-left: 6px;
		font-size: 12px;
		text {
			margin-left: 6px;
		}
	}
}
</style>
